<?php
class registerController extends userController {

	public function index() {
        $this->user_group=model('user_group')->group_list();
        $this->province_list=model('region')->region_list(1,1);
		$this->show();
	}

	public function data() {
        //数据过滤
		$data=in($_POST);
		//基本数据验证
		if(!$_POST['agreement']){
			$this->msg('您未同意注册条款，请先仔细阅读后再同意注册！',0);
		}
		//表单验证
		if(!Check::userName($data['username'],5,12,'/^[x4E00-x9FA5\xf900-xfa2d\w\s]+$/u')||empty($data['username'])){
			$this->msg('用户名只支持5~12位字符，不能有特殊符号',0);
		}

		if(model('user_list')->user_info($_POST['username'])){
            $this->msg('此帐号已存在，请更换帐号名！',0);
        }

		if(!Check::userName($data['nicename'],2,20,'/^[x4E00-x9FA5\xf900-xfa2d\w\s]+$/u')||empty($data['nicename'])){
			$this->msg('昵称只支持2~6位中文',0);
		}

		if(!Check::email($data['email'])||empty($data['email'])){
			$this->msg('邮箱地址输入不正确',0);
		}

		if(!Check::userName($data['password'],6,16,'/[\w\W]+/')||empty($data['password'])){
			$this->msg('密码只支持6~16位字符',0);
		}

		if($data['password']<>$data['password2']){
            $this->msg('两次密码输入不同！',0);
        }

        if(!Check::mobile($data['tel'])||empty($data['tel'])){
			$this->msg('手机号码输入不正确',0);
		}
		if(!Check::userName($data['address'],3,200,'/^[x4E00-x9FA5\xf900-xfa2d\w\.\s]+$/u')||empty($data['address'])){
			$this->msg('请填写正确的地址，不能有特殊符号',0);
		}
		if(!Check::userName($data['qq'],4,12,'/^[1-9][0-9]{4,}$/')){
			$this->msg('qq号码填写不正确',0);
		}

		if(!$data['province']||!$data['city']){
			$this->msg('请选择正确的省市',0);
		}

		$info_config=appConfig('member');
		$name_config=$info_config['APP_SETTING']['reg_user_filter'];
		if(!empty($name_config)){
			$name_array=explode(',', $name_config);
			if(in_array($_POST['username'], $name_array)){
				$this->msg('抱歉您当前的用户名禁止进行注册!');
			}
		}


        $data['password']=md5($data['password']);

		//入库操作
		model('user_list')->add($data);
		$this->msg('注册成功!');

	}

	public function success(){

	}

	public function agreement() {
		echo html_out($this->user_config['reg_agreement']);
	}

	//获取地区
    public function get_province() {
        $pid=intval($_POST['pid']);
        $type=intval($_POST['type']);
        $list=model('region')->region_list($pid,$type);
        $this->msg($list);
    }


}